# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import pymysql

# 连接database
conn = pymysql.connect(host='127.0.0.1', user='root', password='newpassword', database='fix_room_db')
# 得到一个可以执行SQL语句的光标对象
cursor = conn.cursor()

class FixRoomPipeline(object):
    def process_item(self, item, spider):
        part2_title = item['part2_title']
        part2_content= item['part2_content']
        part2_img = item['part2_img']
        i = item['i']
        print('abc'+str(i))

        sql = 'insert into t_room_detail_part2(t_room_detail_id,part2_title,part2_content,part2_img)' \
              'values({},"{}","{}","{}")'.format(i,part2_title,part2_content,part2_img)

        cursor.execute(sql)
        conn.commit()


        # title =  item['title']
        # room_style = item['room_style']
        # room_area = item['room_area']
        # room_count  = item['room_count']
        # room_address = item['room_address']
        #
        # sql = 'insert into t_room_detail(room_title,room_count,room_area,room_style,room_address)' \
        #       ' values("{}","{}","{}","{}","{}")'.format(title,room_count,room_area,room_style,room_address)
        #
        # cursor.execute(sql)
        # conn.commit()


        # href = item['href']
        # sql = 'insert into t_room_href(href) values("{}")'.format(href)
        # cursor.execute(sql)
        # conn.commit()


        pass
        # style = item['style']
        # i = item['i']
        # id = 101 + i
        # sql = 'insert into t_room_style(t_room_title_id,style) values({},"{}")'.format(id,style)
        # cursor.execute(sql)
        # conn.commit()
